package org.tgcloud.group.core;

import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.util.List;
import java.util.Properties;

/**
 * Created by Administrator on 2016/3/28 0028.
 */
public class GlobalStatic {

    /*一分钟以前，1000代表一秒*/
    public static long One_Minute_Ago = 60 * 1000;

    /*验证码长度*/
    public static int Code_Num = 6;

    /*短信未发送*/
    public static short Message_No_Send = 2;

    /*一批发送条数个数*/
    public static int Max_Send_Message = 1000;

    /*短信发送接口*/
    public static String message_send_url;

    /*短信发送账号*/
    public static String message_account;

    /*短信发送密码*/
    public static String message_password;

    public static String uploadPath;

    public static Integer page_size = 10;

    public static Short un_enabled = 2;

    public static Short normal_user = 1; //普通用户

    public static Short com_user = 2; //团长用户

    public static Short manager_user = 3; // 平台管理用户

    public static String qiNiuAK;

    public static String qiNiuSK;

    /*短信类型*/
    public static short MESSAGE_SUBMIT_LOGIN = 10;
    public static short MESSAGE_BACK_PASS = 20;
    public static short MESSAGE_CHANGE_TEL = 30;

    /* 验证码类型 */
    public static final short MESSAGE_REGISTER = 10;
    public static final short MESSAGE_UPDATE_PASSWORD = 20;
    public static final short MESSAGE_UPDATE_ACCOUNT = 30;
    public static final short MESSAGE_CASH_OUT = 40;

    /*五分钟时间*/
    public static long Message_Expire_Time = 5 * 60 * 1000;

    /* 缓存验证码key: 头部 + 账号 + 验证码类型 */
    public static final String EMAIL_HEADER = "email_msg_";
    public static final String PHONE_HERDER = "phone_msg_";

    /* 30天，毫秒数 */
    public static final long THIRTYS_DAYS = 30 * 24 * 60 * 60 * 1000;

    /*首页营销类型：1-严选，2-爆款*/
    public static int recommend_choose = 1;
    public static int recommend_hot = 2;


    /* 用户状态 */
    public static final short user_usable = 1;
    public static final short user_enabled = 2;
    public static final short user_del = 3;


    public static String devMode;

    public static String resourcePath;

    public GlobalStatic() {
    }

    public static void init() {
        Properties pro = new Properties();
        try (InputStream inputStream = GlobalStatic.class.getResourceAsStream("/application.properties")) {
            pro.load(inputStream);
            String dev  = pro.getProperty("spring.profiles.active").trim();
            InputStream in = GlobalStatic.class.getResourceAsStream("/application-" + dev + ".properties");
            pro.load(in);
            if ("dev".equals(dev)) {
                devMode = "dev";
            } else {
                devMode = "dev";
            }
            System.out.println("启动类型======》" + dev);
            downloadPath = pro.getProperty("upload.download.path").trim();
            downloadPic = pro.getProperty("upload.download.pic.path").trim();
            viewFilePath = pro.getProperty("upload.view.path").trim();
            viewPicPath = pro.getProperty("upload.view.pic.path").trim();
            contractURL = pro.getProperty("upload.contract.path").trim();
            viewPicUrl = pro.getProperty("upload.view.pic.url").trim();
            uploadProjectFilePath = pro.getProperty("upload.project.download.path").trim();
            viewProjectFilePath = pro.getProperty("upload.project.view.path").trim();
            InetAddress inetAddress = InetAddress.getLocalHost();
            String ipAddress = inetAddress.getHostAddress();
            // 修改访问的http地址
            if (StringUtil.isNotBlank(ipAddress) && ipAddress.equals("172.31.191.38")){
                viewFilePath = "https://checkorder-view.mejour.cn/download_file";
                viewPicPath = "https://checkorder-view.mejour.cn/download_pic";
                contractURL = "https://checkorder-view.mejour.cn/contract";
                viewPicUrl = "https://check-order.oss-cn-beijing.aliyuncs.com";
                uploadProjectFilePath = "/home/checkorder/project/";
                viewProjectFilePath = "https://checkorder-view.mejour.cn/project/";
            }
//            resourcePath = pro.getProperty("export_path").trim();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 文件上传地址
    public static String uploadProjectFilePath;

    // 文件访问地址
    public static String viewProjectFilePath;

    public static String viewPicUrl;

    public static String contractURL;

    public static String downloadPath;

    public static String downloadPic;

    public static String viewFilePath;

    public static String viewPicPath;

    /*登录成功状态*/
    public static short LOGIN_SUCCESS = 1;

    /*被退出的登录记录*/
    public static short LOGIN_NO = 2;

    public static short enabled = 1;


    /*
    * 公司关联子项目数 缓存头：`company_sub_project_`+`公司id`
    * 公司关联大项目数 缓存头：`company_parent_project_`+`公司id`
    * */
    public static String company_sub_project_head = "company_sub_project_";
    public static String company_parent_project_head = "company_parent_project_";


    /*
    * 角色下用户数量，`role_user_num_` + `角色id`
    * */
    public static String role_user_num = "role_user_num_";


    // 各自的未读状态
    public static String noRead1 = "1";  // 渠道
    public static String noRead2 = "2";  // 开拓者
    public static String noRead3 = "3";  // 订单发布者

    public static String tempChunkFilePath = "/tmp/upload/chunks/"; // 临时分片目录

}
